﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using FreeFlow.Administration;
using FreeFlow.WinFormsControls.HelperClasses;

namespace FreeFlowAdministrator
{
  public partial class WorkflowVersionControl : AdminUserControl
  {
    public WorkflowVersionControl()
    {
      InitializeComponent();

      UIActionList actions = new UIActionList();
      actions.Add("Delete", "Delete this version of the workflow", 
        new ActionExecuteDelegate(DeleteWorkflowVersion));
      uiActionsControl.Actions = actions;
    }

    private WorkflowVersion version;
    public void LoadWorkflowVersion(WorkflowVersion version)
    {
      this.version = version;
      versionLabel.Text = version.Version;
      publishedLabel.Text = version.PublishedTime.ToString();
      typeLabel.Text = version.FullyQualifiedTypeName;
      assemblyLabel.Text = version.FullyQualifiedAssemblyName;
      guidLabel.Text = version.Guid.ToString();
    }

    private string DeleteWorkflowVersion()
    {
      if (MessageBox.Show("Delete this version of the workflow?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
      {
        using (new CursorHandler())
        {
          version.Delete();
        }
        OnItemDeleted();
        Dispose();
      }
      return null;
    }
  }
}
